// 实习岗位数据访问层
package org.example.backend.repository;

import org.example.backend.entity.InternshipPosition;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface InternshipPositionRepository extends JpaRepository<InternshipPosition, Long> {
    Page<InternshipPosition> findByCompanyId(Long companyId, Pageable pageable);

    List<InternshipPosition> findByCompanyIdAndStatus(Long companyId, Integer status);

    @Query("SELECT ip FROM InternshipPosition ip WHERE (:title IS NULL OR ip.title LIKE %:title%) " +
           "AND (:workLocation IS NULL OR ip.workLocation LIKE %:workLocation%) " +
           "AND (:status IS NULL OR ip.status = :status)")
    Page<InternshipPosition> findByConditions(@Param("title") String title,
                                              @Param("workLocation") String workLocation,
                                              @Param("status") Integer status,
                                              Pageable pageable);
}
